<template>
  <el-form-item
    :label="name"
    :prop="code"
    :rules="rules"
  >
    <el-input
      v-model="val"
      :disabled="disabled"
      class="item"
      size="small"
      v-bind="$attrs"
      @change="handleChange"
    />
  </el-form-item>
</template>
<script>
export default {
  name: 'IkFormText',
  model: {
    // 属性
    prop: 'value',
    // 事件
    event: 'input'
  },
  props: {
    code: {
      type: String,
      default: ''
    },
    name: {
      type: String,
      default: ''
    },
    disabled: {
      type: Boolean,
      default: false
    },
    rules: {
      type: Array,
      default: function() {
        return []
      }
    },
    value: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      val: ''
    }
  },
  watch: {
    value: {
      handler(newVal) {
        console.log(newVal)
        this.val = newVal
      }
    }
  },
  methods: {
    handleChange(val) {
      this.$emit('input', val)
    }
  }
}
</script>
